# -*- coding: utf-8 -*-

# __date:       2021/6/16
# __author:     YangChao
# __function:   解析配置文件

import os
import sys

import yaml

config_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + '/config'
# config_path = os.path.dirname(os.path.dirname(os.path.realpath(sys.executable))) + '/config'

def parse_yaml_args(yaml_path=None):
    """
    Parse yaml config info.
    Args:
        yaml_path: yaml file path, default `config/exp.yaml`

    Returns:
        exp_args: ExpArgs object
    """
    if not yaml_path:
        yaml_path = '{}/exp.yaml'.format(config_path)
    with open(yaml_path, mode='r', encoding='utf-8') as fp:
        data = yaml.safe_load(fp)
    return data


def generate_yaml_doc(data, yaml_path=None):
    """
    update yaml config info
    Args:
        data:
        yaml_path:

    Returns:

    """
    if not yaml_path:
        yaml_path = '{}/exp.yaml'.format(config_path)
    file = open(yaml_path, 'w', encoding='utf-8')
    yaml.dump(data, file)
    file.close()

if __name__ == '__main__':
    data = parse_yaml_args()
    print(data)